home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
PIL
/
PpmImagePlugin.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
3KB
|
102 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
__version__ = '0.2'
import string
import Image
import ImageFile
MODES = {
'P4': '1',
'P5': 'L',
'P6': 'RGB',
'P0CMYK': 'CMYK',
'PyP': 'P',
'PyRGBA': 'RGBA',
'PyCMYK': 'CMYK' }
def _accept(prefix):
if prefix[0] == 'P':
pass
return prefix[1] in '0456y'
class PpmImageFile(ImageFile.ImageFile):
format = 'PPM'
format_description = 'Pbmplus image'
def _token(self, s = ''):
while None:
c = self.fp.read(1)
if not c or c in string.whitespace:
break
s = s + c
continue
return s
def _open(self):
s = self.fp.read(1)
if s != 'P':
raise SyntaxError, 'not a PPM file'
mode = MODES[self._token(s)]
if mode == '1':
self.mode = '1'
rawmode = '1;I'
else:
self.mode = rawmode = mode
for ix in range(3):
while None:
while None:
s = self.fp.read(1)
if s not in string.whitespace:
break
continue
continue
if s != '#':
break
s = self.fp.readline()
continue
s = int(self._token(s))
if ix == 0:
xsize = s
continue
if ix == 1:
ysize = s
if mode == '1':
break
mode == '1'
self.size = (xsize, ysize)
self.tile = [
('raw', (0, 0, xsize, ysize), self.fp.tell(), (rawmode, 0, 1))]
def _save(im, fp, filename):
if im.mode == '1':
(rawmode, head) = ('1;I', 'P4')
elif im.mode == 'L':
(rawmode, head) = ('L', 'P5')
elif im.mode == 'RGB':
(rawmode, head) = ('RGB', 'P6')
elif im.mode == 'RGBA':
(rawmode, head) = ('RGB', 'P6')
else:
raise IOError, 'cannot write mode %s as PPM' % im.mode
fp.write(head + '\n%d %d\n' % im.size)
if head != 'P4':
fp.write('255\n')
ImageFile._save(im, fp, [
('raw', (0, 0) + im.size, 0, (rawmode, 0, 1))])
Image.register_open('PPM', PpmImageFile, _accept)
Image.register_save('PPM', _save)
Image.register_extension('PPM', '.pbm')
Image.register_extension('PPM', '.pgm')
Image.register_extension('PPM', '.ppm')